package com.neuedu.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.neuedu.bean.User;
import com.neuedu.dao.IUser;
import com.neuedu.dao.imp.UserImpl;

@WebServlet("/list")
public class UserServlet extends HttpServlet {
   
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	IUser usero=new UserImpl();
	
	//get传值，处理方法
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		doPost(req, resp);
	}
	
	
	//post传值，处理方法
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//从数据库提取的数据
		List<User> listu=usero.selectAll();
		//输出的页面
		//使用的resp对象（响应对象）
		//1:配置：
		resp.setContentType("text/html;charset=utf-8");//文档类型
		resp.setCharacterEncoding("utf-8");//编码
		
		//2:html文件
		PrintWriter out = resp.getWriter();
		out.println("<!DOCTYPE html>");
		out.println("<html>");
		out.println("<body>");
		
		//输出内容
		out.println("<table>");
		for(User u:listu) {
			out.println("<tr><td>"+u.getUid()+"</td><td>"+u.getUname()+"</td></tr>");
		}
		
		out.println("</table>");
		
		
		
		
		out.println("</body>");
		
		out.println("</html>");
		
	}
}
